home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet multimedia / Animacje, filmy i prezentacje / Modelowanie 3D / K-3D 0.6.5.0 / k3d-all-in-one-setup-0.6.5.0.exe / k3d-setup-0.6.5.0.exe / share / shaders / k3d_tile.h < prev   
Encoding:
Text File  |  2004-05-19  |  2.4 KB  |  53 lines

  1. /*     tile.h
  2.         a file to produce an antaliased tiling pattern
  3. */
  4.  
  5.  
  6.  
  7. /* this function considers a square wave pulse, with a given period and width,
  8. the width being expressed as a proportion of the period, and so varying between 0 and 1 */
  9. float integratedpulse (                    float x, pulseperiod, pulsewidth;
  10.                                                 output    float which, offset)
  11.     {
  12.         float where = x / pulseperiod;
  13.         which = floor(where);
  14.         offset = where - which;
  15.         /* sum up the contribution of all tiles except the present */
  16.         float basetotal = which * pulsewidth;
  17.         float thistile = offset - min(max(0, offset - pulsewidth / 2), 1 - pulsewidth);
  18.         return (thistile + basetotal) * pulseperiod;
  19.     } 
  20.  
  21. /*
  22. Given the dimensions of a series of tiles, works out which tile we are in, and the
  23. coordinates within that tile (normalized to the range 0 - 1). It returns a float
  24. representing a filtered calculation of the extent the current micropolygon lies
  25. within an edge (1 = all within edge, 0 = all within tile).
  26. Note that the parameters sedge, tedge give the total width of the edge, so that e.g there
  27. will be an edge of width sedge / 2 on both the left and right of the tile 
  28. */
  29.  
  30. float tile(        float ss,                                    /* current s texture coordinate */
  31.                                         tt,                                 /* current t texture coordinate */
  32.                                         swidth,                         /* width of tile in s direction */
  33.                                         twidth,                         /* width of tile in t direction */
  34.                                         sfiltwidth,                 /* size of antalias filter in s direction */
  35.                                         tfiltwidth,                 /* size of antalias filter in t direction */
  36.                                         sedge,                             /* tile edge in t direction, as a proportion of tile size (0 - 1)*/
  37.                                         tedge;                            /* tile edge in s direction, as a proportion of tile size (0 - 1)*/
  38.                             output float     swhich,            /* s coordinate of which tile we are in (an integer) */
  39.                                                          twhich,            /* t coordinate of which tile we are in (an integer) */
  40.                                                          soffset,        /* s offset within tile (0 - 1) */
  41.                                                         toffset)        /* t offset within tile (0 - 1) */
  42.     {
  43.         float sintegral = integratedpulse(ss + sfiltwidth, swidth, sedge, swhich, soffset);     
  44.         float tintegral = integratedpulse(tt + tfiltwidth, twidth, tedge, twhich, toffset);     
  45.         sintegral = abs(sintegral - integratedpulse(ss, swidth, sedge, swhich, soffset)) 
  46.             /sfiltwidth;
  47.         tintegral = abs(tintegral - integratedpulse(tt, twidth, tedge, twhich, toffset)) 
  48.             /tfiltwidth;
  49.         /*printf("soffset = %f\tsfiltwidth = %f\tsintegral = %f\n",soffset,sfiltwidth, sintegral); */
  50.         return max(sintegral, tintegral);
  51.     }
  52.  
  53.